package algorithm.搜索法;

public class Contact implements Comparable{
    String firstname;
    String lastname;
    String phone;

    public Contact(String firstname, String lastname, String phone) {
        this.firstname = firstname;
        this.lastname = lastname;
        this.phone = phone;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public String toString() {
        return "Contact{" +
                "firstname='" + firstname + '\'' +
                ", lastname='" + lastname + '\'' +
                ", phone='" + phone + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object obj) {
        return (lastname.equals(((Contact)obj).getLastname())&&firstname.equals(((Contact)obj).getFirstname()));
    }

    @Override
    public int compareTo(Object o) {
        int result;
      String otherFirst=((Contact)o).getFirstname();
      String otherLast=((Contact)o).getLastname();
      if (lastname.equals(otherLast)){
          result=firstname.compareTo(otherFirst);
      }else {
          result=lastname.compareTo(otherLast);
      }
      return result;
    }
}
